// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
//引入elementui
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import VueAMap from 'vue-amap';
axios.defaults.baseURL = "http://localhost:9091"

//将axions对象挂载到vue的原型对象上，此后在组件中就可以使用this.$http来访问axions对象,而不必在每个组件中去import axios
Vue.prototype.$http = axios
//将elemengtUi绑定到Vue原型对象上
Vue.use(ElementUI);

Vue.config.productionTip = false


// 添加请求拦截器
axios.interceptors.request.use(function(config) {
  let token = localStorage.getItem("token");
  if (token) {
    config.headers["token"] = token;
  }
  return config;
});


// 添加响应拦截器
axios.interceptors.response.use(function(resp) {


  if (resp.data.code == "401") { //未登录或者JWT无效的情况
    router.push("/")
  }
  if (resp.data.code == "200") {

    let id = resp.headers["id"];

    let token = resp.headers["token"];
    localStorage.setItem("id", id);
    if (token) {
      localStorage.setItem("token", token);

    }
  }

  return resp;
});
//初始话高德地图
VueAMap.initAMapApiLoader({
  Key:'c523bd172eed0a9fbd221d0e34663da7',
  Plugin:[
    'AMap.Autocomplete',
    'AMap.PlaceSearch',
    'AMap.Scale',
    'AMap.OverView',
    'AMap.ToolBar',
    'AMap.MapType',
    'AMap.PolyEditor',
    'AMap.CircleEditor',
  ],
  v: '1.4.15'
});



/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
